package com.itheima.supermarket.manage.servicer;

import com.itheima.supermarket.manage.dao.FruitDao;
import com.itheima.supermarket.manage.domain.Fruits;

import java.io.IOException;
import java.util.ArrayList;

public class FruitServicer {
    //创建水果库集合对象
    FruitDao fd = new FruitDao();

    //判断水果库中是否还有水果
    //判断水果集合是否为空
    public boolean isExsits(String number) {
        ArrayList<Fruits> fruits = getFruits();
        boolean flag = false;
        if (fruits != null) {
            for (Fruits fruit : fruits) {
                if (fruit.getNumber().equals(number)) {
                    flag = true;
                    break;
                }
            }
        }
        return flag;
    }

    //获取水果集合
    public ArrayList<Fruits> getFruits() {
        //拿到水果集合
        ArrayList<Fruits> fruits = null;
        fruits = fd.getList();
        return fruits;
    }

    //添加水果
    public void addFruits(Fruits fruits) {
        fd.addFruits(fruits);
    }

    //删除水果
    public void deleteFruits(String number) {
        fd.deleteFruits(number);
    }

    //修改水果
    public void updateFruits(Fruits fruit, String number) {
        fd.updateFruits(fruit, number);
    }
}
